package com.xiu.travel.file.oss.controller;

import com.xiu.travel.file.oss.domain.OssCallbackResult;
import com.xiu.travel.file.oss.domain.OssPolicyResult;
import com.xiu.travel.util.api.CommonResult;
import com.xiu.travel.file.oss.service.impl.OssServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lijie
 * @date 2023/5/12 11:54
 * @description OssController
 *
 * Oss相关操作接口
 */
@RestController
@RequestMapping("admin/open/aliyun/oss")
@Tag(  name = "oss文件上传接口")
public class OssController
{
    @Autowired
    private OssServiceImpl ossService;

    @Operation(summary = "oss上传签名生成")
    @GetMapping("/policy")
    public CommonResult<OssPolicyResult> policy() {
        OssPolicyResult result = ossService.policy();
        return CommonResult.success(result);
    }

    @Operation(summary = "oss上传成功回调")
    @PostMapping("callback")
    public CommonResult<OssCallbackResult> callback(HttpServletRequest request) {
        OssCallbackResult ossCallbackResult = ossService.callback(request);
        return CommonResult.success(ossCallbackResult);
    }

    @PostMapping("fileUpload")
    @Operation(summary = "文件上传接口")
    public CommonResult<String> upFile(@RequestParam("file") @Parameter(description = "上传文件") MultipartFile file) throws Exception
    {
        return ossService.upFile(file);
    }
}
